#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
  int totalFruit(vector<int> &fruits)
  {
    int ans = 0;
    unordered_map<int, int> cnt;
    int left = 0;
    for (int i = 0; i < fruits.size(); i++)
    {
      cnt[fruits[i]] += 1;
      if (cnt.size() > 2)
      {
        while (cnt[fruits[left]]--)
        {
          if (cnt[fruits[left]] == 0)
          {
            cnt.erase(fruits[left++]);
            break;
          }
          left += 1;
        }
      }
      ans = max(ans, i - left + 1);
    }
    return ans;
  }
};
int main()
{
  Solution s;

  return 0;
}
